package org.linlinjava.litemall.wx.controller;

import org.linlinjava.litemall.core.util.ResponseUtil;
import org.linlinjava.litemall.wx.annotation.LoginUser;
import org.linlinjava.litemall.wx.service.WxBarcodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * wx条形码控制器
 *
 * @author yliyun
 * @description：二维码生成器controller
 * @date 2022/09/14
 */

@RestController
@RequestMapping("/wx/barcode")
public class WxBarCodeController {
    /**
     * wx条码服务
     */
    @Autowired
    private WxBarcodeService wxBarcodeService;

    /**
     * 得到条形码
     *
     * @param userId 用户id
     * @param cardId 卡id
     * @return {@link Object}
     * @throws Exception 异常
     */
    @GetMapping("/generate")
    public Object getBarcode(@LoginUser Integer userId, Integer cardId) throws Exception {
        if(userId == null){return ResponseUtil.unlogin();}
        return cardId==null?wxBarcodeService.balancePaymentCode(userId):wxBarcodeService.giftCardPaymentCode(cardId);
    }
}
